// 使用示例
loadScript('https://h5.wan.liebao.cn/h5/gameH5Sdk.js', function(err) {
    if (err) {
        console.error('加载出错');
    } else {
        console.log('加载成功');
        // 在这里使用加载的库
        // 初始化
        WanGameH5sdk.config();
        // 登录
        lb_login();
        console.log("是否打开游戏：",open_game);
        if(!open_game){
            open_game = 1;

            WanGameH5sdk.log({
                action: 'game_onserver',
            });
            // 进入游戏
            WanGameH5sdk.log({
                action: 'game_access',
                server_id: data.sid,
                server_name: data.sid,
                role_id: data.role_id,
                role_name: data.role_name,
                role_level: data.role_level,
                is_vip: '0',
                vip_level: '0',
                power: data.role_power
            });

        }
    }
});

function lb_login(){
    var queryParams = getQueryParams();
    console.log(queryParams);
    queryParams.cid = cid;
    queryParams.gid = gid;
    faXingLogin(queryParams);
}

function getQueryParams() {
    var urlParams = new URLSearchParams(window.location.search);
    var params = {};
    for (var param of urlParams.entries()) {
        params[param[0]] = param[1];
    }
    return params;
}



function liebao_creterole(data){


    if(data.is_save == 1){

        console.log("猎豹发行角色更新：",{
            action:'game_levelup',
            actionvalue:data.role_level,
            server_id: data.sid,
            server_name: data.sid,
            role_id: data.role_id,
            role_name: data.role_name,
            is_vip: '0',
            vip_level: '0',
            power: data.role_power
        });
        WanGameH5sdk.log({
            action:'game_levelup',
            actionvalue:data.role_level,
            server_id: data.sid,
            server_name: data.sid,
            role_id: data.role_id,
            role_name: data.role_name,
            is_vip: '0',
            vip_level: '0',
            power: data.role_power
        });
    }else{
        console.log("猎豹发行角色创建：",data);
        WanGameH5sdk.log({
            action: 'create_role',
            server_id: data.sid,
            server_name: data.sid,
            role_id: data.role_id,
            role_name: data.role_name,
            role_level: data.role_level,
            is_vip: '0',
            vip_level: '0',
            power: data.role_power
        });
    }
}



function liebao_pay(data){
    console.log("猎豹支付数据：",data);
    WanGameH5sdk.placeOrder({data:data});
}
